package com.bx.implatform;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.*;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.util.concurrent.DefaultPromise;

import java.util.concurrent.ExecutionException;

/**
 * @author YuJiaMing
 * date 2024年06月17日 16:43
 */
public class Test {


    public static void main(String[] args) throws ExecutionException, InterruptedException {


        System.out.println(System.currentTimeMillis());

        EventLoopGroup eventLoopGroup = new NioEventLoopGroup();
        EventLoop eventLoop = eventLoopGroup.next();


        DefaultPromise<Object> promise = new DefaultPromise<>(eventLoop);


        new Thread(()->{
            promise.setSuccess("123213");

        }).start();


        System.out.println("获取---" + promise.get());
        System.out.println("结束了");



        new ServerBootstrap()
                .group(new NioEventLoopGroup(),new NioEventLoopGroup())
                .channel(NioServerSocketChannel.class)
                .childHandler(new ChannelInitializer<SocketChannel>() {
                    @Override
                    protected void initChannel(SocketChannel socketChannel) throws Exception {

                        socketChannel.pipeline()
                                .addLast(new ChannelInboundHandlerAdapter(){
                                    @Override
                                    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {

                                        super.channelRead(ctx, msg);
                                    }
                                });

                    }
                }).bind(19999);

    }

}
